package com.asl.website.companyContact.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.companyContact.domain.CompanyContactDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.companyContact.domain.CompanyContact;
import com.asl.website.companyContact.service.ICompanyContactService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * 公司联系信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/companyContact/companyContact")
public class CompanyContactController extends BaseController
{
    @Autowired
    private ICompanyContactService companyContactService;
    /**
     * 获取公司联系信息
     */
    @GetMapping("/content")
    public AjaxResult getCompanyContact(
            @RequestHeader(value = "Accept-Language", defaultValue = "zh-CN") String acceptLanguage) {

        List<CompanyContact> contact = companyContactService.selectCompanyContactList(new CompanyContact());
        if (contact == null) {
            return AjaxResult.error("公司联系信息未配置");
        }

        return AjaxResult.success(new CompanyContactDTO(contact.get(0), acceptLanguage));
    }
    /**
     * 查询公司联系信息列表
     */
    @PreAuthorize("@ss.hasPermi('companyContact:companyContact:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyContact companyContact)
    {
        startPage();
        List<CompanyContact> list = companyContactService.selectCompanyContactList(companyContact);
        return getDataTable(list);
    }

    /**
     * 导出公司联系信息列表
     */
    @PreAuthorize("@ss.hasPermi('companyContact:companyContact:export')")
    @Log(title = "公司联系信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompanyContact companyContact)
    {
        List<CompanyContact> list = companyContactService.selectCompanyContactList(companyContact);
        ExcelUtil<CompanyContact> util = new ExcelUtil<CompanyContact>(CompanyContact.class);
        util.exportExcel(response, list, "公司联系信息数据");
    }

    /**
     * 获取公司联系信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('companyContact:companyContact:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(companyContactService.selectCompanyContactById(id));
    }

    /**
     * 新增公司联系信息
     */
    @PreAuthorize("@ss.hasPermi('companyContact:companyContact:add')")
    @Log(title = "公司联系信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyContact companyContact)
    {
        return toAjax(companyContactService.insertCompanyContact(companyContact));
    }

    /**
     * 修改公司联系信息
     */
    @PreAuthorize("@ss.hasPermi('companyContact:companyContact:edit')")
    @Log(title = "公司联系信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyContact companyContact)
    {
        return toAjax(companyContactService.updateCompanyContact(companyContact));
    }

    /**
     * 删除公司联系信息
     */
    @PreAuthorize("@ss.hasPermi('companyContact:companyContact:remove')")
    @Log(title = "公司联系信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(companyContactService.deleteCompanyContactByIds(ids));
    }
}
